home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / m2gem106.lzh / CRYSTAL1.06 / TST / SAMPLE / SAMPLE.M2
Encoding:
Text File  |  1993-06-13  |  10.8 KB  |  418 lines

  1. (***************************************************************************)
  2. (* GEM sample application                                                  *)
  3. (* adapted from apskel.c by Ron Zdybl, Atari Corp.                         *)
  4. (*                                                                         *)
  5. (* UK 06/13/1993                                                           *)
  6. (***************************************************************************)
  7.  
  8. MODULE Sample;
  9.  
  10. FROM AES        IMPORT Root,ObjectIndex,TreeIndex,TreePtr,
  11.                        StringPtr,ObjectState,Selected,Checked,State15;
  12. FROM ApplMgr    IMPORT ApplInit,ApplExit,ApplWrite;
  13. FROM EvntMgr    IMPORT EvntEvent,MEvent,MuMesag,Event,
  14.                        MessageBlock,Messages,ApTerm;
  15. FROM FormMgr    IMPORT FmDStart,FmDGrow,FmDShrink,FmDFinish,FormDial,
  16.                        FormCenter,FormDo;
  17. FROM ObjcMgr    IMPORT ObjcDraw,MaxDepth,ObjcOffset,ObjcFind,ObjcChange;
  18. FROM MenuMgr    IMPORT MenuBar,MenuText,MenuTNormal,MenuICheck;
  19. FROM GrafMgr    IMPORT GrafHandle,GrafGrowBox,GrafShrinkBox;
  20. FROM RsrcMgr    IMPORT RsrcLoad,RsrcFree;
  21. FROM WindMgr    IMPORT NoWindow,Desk,WindCreate,WindOpen,WindClose,
  22.                        WindDelete,WindCalc,WCBorder,WCWork,
  23.                        WindowElement,WindowElements;
  24. FROM RcMgr      IMPORT GRect,GPnt,RcIntersect,RcEqual;
  25. FROM ObjcTool   IMPORT ObjectXYWH,INCLObjectState,EXCLObjectState;
  26. FROM FormTool   IMPORT OK,Alert,Mask;
  27. FROM RsrcTool   IMPORT GetTreePtr,GetStringPtr;
  28. FROM GrafTool   IMPORT ShowMouse,HideMouse,BusyMouse,ArrowMouse;
  29. FROM WindTool   IMPORT GetWorkXYWH,GetFirstXYWH,GetNextXYWH,SetTop,
  30.                        SetName,SetInfo,SetCurrXYWH,GetCurrXYWH,
  31.                        GetFullXYWH,GetPrevXYWH,
  32.                        BeginUpdate,EndUpdate,
  33.                        BeginMouseControl,EndMouseControl;
  34. FROM VDI        IMPORT XY,White,Black;
  35. FROM VAttribute IMPORT VSFInterior,FISPattern,VSFStyle,VSFColor;
  36. FROM VOutput    IMPORT VBar,VEllipse;
  37. FROM VDITool    IMPORT OpenVirtualWorkstation,CloseVirtualWorkstation,
  38.                        SetClip,GRectToArray;
  39. FROM INTRINSIC  IMPORT VOID,PTR;
  40. FROM PORTAB     IMPORT UNSIGNEDWORD,SIGNEDWORD,ANYWORD;
  41.  
  42. IMPORT SetObject,GetObject;
  43.  
  44. (* Resource Indices *)
  45.  
  46. CONST
  47.  
  48.     MENU     =   0;    (* Menuebaum *)
  49.     TINFO    =   3;    (* TITLE in Baum MENU *)
  50.     TFILE    =   4;    (* TITLE in Baum MENU *)
  51.     TEDIT    =   5;    (* TITLE in Baum MENU *)
  52.     TOPTION  =   6;    (* TITLE in Baum MENU *)
  53.     IINFO    =   9;    (* STRING in Baum MENU *)
  54.     INEW     =  18;    (* STRING in Baum MENU *)
  55.     IABORT   =  24;    (* STRING in Baum MENU *)
  56.     IQUIT    =  27;    (* STRING in Baum MENU *)
  57.     ICUT     =  31;    (* STRING in Baum MENU *)
  58.     ICOPY    =  32;    (* STRING in Baum MENU *)
  59.     IPASTE   =  33;    (* STRING in Baum MENU *)
  60.     IWARNING =  37;    (* STRING in Baum MENU *)
  61.     IHELP    =  38;    (* STRING in Baum MENU *)
  62.     IOPTSAVE =  40;    (* STRING in Baum MENU *)
  63.  
  64.     INFO     =   1;    (* Formular/Dialog *)
  65.     INFOK    =   1;    (* BUTTON in Baum INFO *)
  66.  
  67.     WNAME    =   0;    (* Freier String *)
  68.  
  69.     WINFO    =   1;    (* Freier String *)
  70.  
  71.     HELPON   =   2;    (* Freier String *)
  72.  
  73.     HELPOFF  =   3;    (* Freier String *)
  74.  
  75.     NOWIND   =   4;    (* Alert String *)
  76.  
  77.     NOVWORK  =   5;    (* Alert String *)
  78.  
  79.     QUIT     =   6;    (* Alert String *)
  80.  
  81. PROCEDURE MAIN;
  82.  
  83. CONST RscName   = "SAMPLE.RSC";
  84.       MyFeature = WindowElement{Name,Close,Full,Move,Info,Size};
  85.  
  86. VAR ApplId    : SIGNEDWORD;
  87.     VirtScreen: UNSIGNEDWORD;
  88.     MyMenu    : TreePtr;
  89.     MyName    : StringPtr;
  90.     MyInfo    : StringPtr;
  91.     HelpItem  : StringPtr;
  92.     MyWindow  : SIGNEDWORD;
  93.     Work      : GRect;
  94.     XEll      : UNSIGNEDWORD;
  95.     YEll      : UNSIGNEDWORD;
  96.     WEll      : UNSIGNEDWORD;
  97.     HEll      : UNSIGNEDWORD;
  98.     CharWidth : UNSIGNEDWORD;
  99.     CharHeight: UNSIGNEDWORD;
  100.     BoxWidth  : UNSIGNEDWORD;
  101.     BoxHeight : UNSIGNEDWORD;
  102.     MinWidth  : SIGNEDWORD;
  103.     MinHeight : SIGNEDWORD;
  104.  
  105.   PROCEDURE OpenWindow(VAR Window: SIGNEDWORD): BOOLEAN;
  106.  
  107.   VAR Start : GRect;
  108.       Full  : GRect;
  109.  
  110.   BEGIN
  111.     GetWorkXYWH(Desk,Full);
  112.     Window:= WindCreate(MyFeature,Full);
  113.     IF Window # NoWindow THEN
  114.  
  115.       MyName:= GetStringPtr(WNAME);
  116.       SetName(Window,MyName^);
  117.  
  118.       MyInfo:= GetStringPtr(WINFO);
  119.       SetInfo(Window,MyInfo^);
  120.  
  121.       WITH Full DO
  122.         Start.GX:= GX + GW DIV 2;
  123.         Start.GY:= GY + GH DIV 2;
  124.         Start.GW:= BoxWidth;
  125.         Start.GH:= BoxHeight;
  126.       END;
  127.  
  128.       GrafGrowBox(Start,Full);
  129.       WindOpen(Window,Full);
  130.     END;
  131.     RETURN Window # NoWindow;
  132.   END OpenWindow;
  133.  
  134.   PROCEDURE CloseWindow(Window: SIGNEDWORD);
  135.  
  136.   VAR Start: GRect;
  137.       End  : GRect;
  138.       Full : GRect;
  139.  
  140.   BEGIN
  141.     GetCurrXYWH(Window,Start);
  142.     GetWorkXYWH(Desk,Full);
  143.  
  144.     WITH Full DO
  145.       End.GX:= GW DIV 2;
  146.       End.GY:= GH DIV 2;
  147.       End.GW:= BoxWidth;
  148.       End.GH:= BoxHeight;
  149.     END;
  150.  
  151.     WindClose(Window);
  152.     GrafShrinkBox(End,Start);
  153.     WindDelete(Window);
  154.   END CloseWindow;
  155.  
  156.   PROCEDURE DoRedraw(Window: SIGNEDWORD; VAR Clip: GRect);
  157.  
  158.   VAR Rect: GRect;
  159.  
  160.     PROCEDURE DrawSample(Handle: UNSIGNEDWORD);
  161.  
  162.     VAR Points: ARRAY[0..3] OF XY;
  163.         Work  : GRect;
  164.  
  165.     BEGIN
  166.       VSFInterior(Handle,FISPattern);
  167.       VSFStyle(Handle,8);
  168.       VSFColor(Handle,White);
  169.       GetWorkXYWH(MyWindow,Work);
  170.       GRectToArray(Work,Points);
  171.       VBar(Handle,Points);
  172.  
  173.       XEll:= Work.GX;
  174.       YEll:= Work.GY;
  175.       VSFInterior(Handle,FISPattern);
  176.       VSFStyle(Handle,8);
  177.       VSFColor(Handle,Black);
  178.       VEllipse(Handle,XEll + WEll DIV 2,YEll + HEll DIV 2,
  179.                       WEll DIV 2,HEll DIV 2);
  180.     END DrawSample;
  181.  
  182.   BEGIN
  183.     HideMouse;
  184.     BeginUpdate;
  185.  
  186.     GetFirstXYWH(Window,Rect);
  187.  
  188.     WITH Rect DO
  189.       WHILE (GW # 0) AND (GH # 0) DO
  190.         IF RcIntersect(Clip,Rect) THEN
  191.           SetClip(VirtScreen,Rect);
  192.           DrawSample(VirtScreen);
  193.         END;
  194.         GetNextXYWH(Window,Rect);
  195.       END;
  196.     END;
  197.  
  198.     EndUpdate;
  199.     ShowMouse;
  200.   END DoRedraw;
  201.  
  202.   PROCEDURE DoSize(Window: SIGNEDWORD; VAR Rect: GRect);
  203.   BEGIN
  204.     WITH Rect DO
  205.       IF GW < MinWidth THEN
  206.         GW:= MinWidth;
  207.       END;
  208.       IF GH < MinHeight THEN
  209.         GH:= MinHeight;
  210.       END;
  211.     END;
  212.     SetCurrXYWH(Window,Rect);
  213.   END DoSize;
  214.  
  215.   PROCEDURE DoFull(Window: SIGNEDWORD);
  216.  
  217.   VAR Prev: GRect;
  218.       Curr: GRect;
  219.       Full: GRect;
  220.  
  221.   BEGIN
  222.     GetFullXYWH(Window,Full);
  223.     GetCurrXYWH(Window,Curr);
  224.     GetPrevXYWH(Window,Prev);
  225.     IF RcEqual(Curr,Full) THEN
  226.       GrafShrinkBox(Prev,Full);
  227.       SetCurrXYWH(Window,Prev);
  228.     ELSE
  229.       GrafGrowBox(Curr,Full);
  230.       SetCurrXYWH(Window,Full);
  231.     END;
  232.   END DoFull;
  233.  
  234.   PROCEDURE DoClose(Window: SIGNEDWORD);
  235.  
  236.   VAR MyMessage: MessageBlock;
  237.  
  238.   BEGIN
  239.     WITH MyMessage DO
  240.       Type  := MnSelected;
  241.       Id    := ApplId;
  242.       Length:= 0;
  243.       Title := TFILE;
  244.       Item  := IQUIT;
  245.     END;
  246.     ApplWrite(ApplId,16,MyMessage);
  247.   END DoClose;
  248.  
  249.   PROCEDURE DoMenu(Title: ObjectIndex; Item: ObjectIndex);
  250.  
  251.   VAR Box : GRect;
  252.  
  253.     PROCEDURE DoForm(    TreeNo: TreeIndex;
  254.                          Start : ObjectIndex;
  255.                      VAR From  : GRect): ObjectIndex;
  256.  
  257.     VAR Tree  : TreePtr;
  258.         To    : GRect;
  259.         Return: SIGNEDWORD;
  260.  
  261.     BEGIN
  262.       BeginUpdate;
  263.       Tree:= GetTreePtr(TreeNo);
  264.       FormCenter(Tree,To);
  265.       FormDial(FmDStart,To,To);
  266.       FormDial(FmDGrow,From,To);
  267.       ObjcDraw(Tree,Root,MaxDepth,To);
  268.       Return:= Mask(FormDo(Tree,Start));
  269.       ObjcChange(Tree,Return,1,To,
  270.                  GetObject.State(Tree,Return) - ObjectState{Selected},
  271.                  FALSE);
  272.       FormDial(FmDShrink,From,To);
  273.       FormDial(FmDFinish,To,To);
  274.       EndUpdate;
  275.       RETURN Return;
  276.     END DoForm;
  277.  
  278.   BEGIN
  279.     ArrowMouse;
  280.     CASE Title OF
  281.       TINFO:
  282.         CASE Item OF
  283.           IINFO:
  284.             ObjectXYWH(MyMenu,TINFO,Box);
  285.             VOID(DoForm(INFO,0,Box));
  286.         ELSE
  287.           ;
  288.         END;
  289.     | TFILE:
  290.         ;
  291.     | TEDIT:
  292.         ;
  293.     | TOPTION:
  294.         CASE Item OF
  295.           IWARNING:
  296.              MenuICheck(MyMenu,IWARNING,NOT(Checked IN GetObject.State(MyMenu,IWARNING)));
  297.         | IHELP:
  298.             IF State15 IN GetObject.State(MyMenu,IHELP) THEN
  299.               HelpItem:= GetStringPtr(HELPOFF);
  300.               EXCLObjectState(MyMenu,IHELP,State15);
  301.             ELSE
  302.               HelpItem:= GetStringPtr(HELPON);
  303.               INCLObjectState(MyMenu,IHELP,State15);
  304.             END;
  305.             MenuText(MyMenu,IHELP,HelpItem^);
  306.         ELSE
  307.           ;
  308.         END;
  309.         ;
  310.     ELSE
  311.       ;
  312.     END;
  313.     MenuTNormal(MyMenu,Title,TRUE);
  314.   END DoMenu;
  315.  
  316.   PROCEDURE EventLoop;
  317.  
  318.   VAR EventBlock: MEvent;
  319.       MyEvent   : Event;
  320.       MyMessage : MessageBlock;
  321.  
  322.   BEGIN
  323.     WITH EventBlock DO
  324.       EFlags:= Event{MuMesag};
  325.       EMePBuf:= PTR(MyMessage);
  326.  
  327.       WITH MyMessage DO
  328.         LOOP
  329.           MyEvent:= EvntEvent(EventBlock);
  330.  
  331.           IF MuMesag IN MyEvent THEN
  332.             CASE Type OF
  333.               WMRedraw:
  334.                 DoRedraw(Handle,Rect);
  335.             | WMNewTop:
  336.                 SetTop(Handle);
  337.             | WMTopped:
  338.                 SetTop(Handle);
  339.             | WMSized:
  340.                 DoSize(Handle,Rect);
  341.             | WMMoved:
  342.                 SetCurrXYWH(Handle,Rect);
  343.             | WMFulled:
  344.                 DoFull(Handle);
  345.             | WMClosed,ApTerm:
  346.                 DoClose(Handle);
  347.             | MnSelected:
  348.                 DoMenu(Title,Item);
  349.             ELSE
  350.               ;
  351.             END;
  352.           END;
  353.  
  354.           IF (Type = MnSelected) AND (Item = IQUIT) THEN
  355.             IF OK(QUIT) THEN
  356.               EXIT;
  357.             END;
  358.           END;
  359.  
  360.         END;
  361.       END;
  362.     END;
  363.   END EventLoop;
  364.  
  365. BEGIN
  366.   ApplId:= ApplInit();
  367.  
  368.   IF ApplId < 0 THEN
  369.     RETURN;
  370.   END;
  371.  
  372.   BeginUpdate;
  373.   BusyMouse;
  374.  
  375.   IF RsrcLoad(RscName) THEN
  376.     IF OpenVirtualWorkstation(VirtScreen) THEN
  377.       MyMenu:= GetTreePtr(MENU);
  378.       VOID(MenuBar(MyMenu,1));
  379.  
  380.       VOID(GrafHandle(CharWidth,CharHeight,BoxWidth,BoxHeight));
  381.       MinWidth:= 2 * BoxWidth;
  382.       MinHeight:= 2 * BoxHeight;
  383.  
  384.       IF OpenWindow(MyWindow) THEN
  385.         ArrowMouse;
  386.         EndUpdate;
  387.  
  388.         GetWorkXYWH(MyWindow,Work);
  389.         WITH Work DO
  390.           XEll:= GX;
  391.           YEll:= GY;
  392.           WEll:= GW;
  393.           HEll:= GH;
  394.         END;
  395.  
  396.         EventLoop;
  397.  
  398.         CloseWindow(MyWindow);
  399.       ELSE
  400.         Alert(NOWIND);
  401.       END;
  402.       VOID(MenuBar(MyMenu,0));
  403.       CloseVirtualWorkstation(VirtScreen);
  404.     ELSE
  405.       Alert(NOVWORK);
  406.     END;
  407.     RsrcFree;
  408.   ELSE
  409.     EndUpdate;
  410.   END;
  411.   ApplExit;
  412. END MAIN;
  413.  
  414. BEGIN
  415.   MAIN;
  416. END Sample.
  417.  
  418.